package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.GreTransplantDao;
import cn.topevery.garden.entity.po.GreTransplant;
import cn.topevery.garden.entity.query.GreTransplantQuery;
import cn.topevery.garden.entity.vo.GreTransplantVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import hw.topevery.framework.entity.KeyValue;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 占绿移植信息管理表
 *
 * @author code-generate
 * @date 2023-03-03
 */
@Repository
public class GreTransplantDaoImpl extends BaseDaoImpl<GreTransplant> implements GreTransplantDao {
    @Override
    public <P extends DbCsp> List<GreTransplant> getSearch(P para) {
        return null;
    }


    @Override
    public DataPager<GreTransplantVO> listPage(GreTransplantQuery query) {
        String table = "t_gre_transplant tgt";

        String columns = "tgt.*";

        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tgt.c_id desc");
        sqlQueryMate
                .where(true, "tgt.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(StringUtils.isNotBlank(query.getCode()), "tgt.c_code", ScriptConditionEnum.Eq, query.getCode());

        return getDataPager(sqlQueryMate, pageSize, pageIndex, GreTransplantVO.class);
    }

    @Override
    public GreTransplant getEntityByColumn(String key, String value) {
        KeyValue<String> map = new KeyValue<>();
        map.key = key;
        map.value = value;
        return getEntityByColumnEqValue(map);
    }
}
